package sparkExamples.exerciseDemo

import org.apache.spark.{SparkConf, SparkContext}

object ExerciseDemo09 {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("ExerciseDemo").setMaster("local[*]")
    val sparkContext = new SparkContext(conf)

    val txtRDD = sparkContext.textFile("src\\main\\scala\\data\\exerciseData.txt")
    txtRDD.cache()

    /**
     * 19、12班语文成绩最低分是多少？
     * 20、13班数学最高成绩是多少？
     */
    val minCinese12:Int = txtRDD.filter {
      line => {
        val data = line.split(" ")
        if (data(0) == "12" && data(4) == "chinese") true else false
      }
    }.map(_.split(" ")(5).toInt).collect().min

    println("12班语文成绩最低分:" + minCinese12)

    sparkContext.stop()
  }

}
